function C57_CPP_saline_altcontext_rm_cdf(Data_Summary)
%% 24h saline data
C5_saline_RM = [];
for n = 1:size(Data_Summary,2)
    if strcmp(Data_Summary(n).animalName, 'C57_5') && strcmp(Data_Summary(n).drug,'saline')  && isempty(C5_saline_RM)
        [RM, RM_Shuffle] = get_RM_values_ready(Data_Summary(n).Rate_Map_Corr, Data_Summary(n).Shuffled_Rate_Map_Corr_values, Data_Summary(n).RateMap_Corr_Coherent_Rot);
        C5_saline_RM = RM;
        C5_saline_Shuffle = RM_Shuffle;
    elseif strcmp(Data_Summary(n).animalName, 'C57_5') && strcmp(Data_Summary(n).drug,'saline')   && ~isempty(C5_saline_RM)
        [RM, RM_Shuffle] = get_RM_values_ready(Data_Summary(n).Rate_Map_Corr, Data_Summary(n).Shuffled_Rate_Map_Corr_values, Data_Summary(n).RateMap_Corr_Coherent_Rot);
        C5_saline_RM = cat(1,C5_saline_RM,RM);
        C5_saline_Shuffle = cat(1,C5_saline_Shuffle,RM_Shuffle);
    end
end
[C5sf,C5sx,C5slow,C5shigh] = ecdf(C5_saline_RM,'Function','cdf','Alpha',0.05);
[C5ssf,C5ssx,C5sslow,C5sshigh] = ecdf(C5_saline_Shuffle,'Function','cdf','Alpha',0.05);

C6_saline_RM = [];
for n = 1:size(Data_Summary,2)
    if strcmp(Data_Summary(n).animalName, 'C57_6') && strcmp(Data_Summary(n).drug,'saline')  && isempty(C6_saline_RM)
        [RM, RM_Shuffle] = get_RM_values_ready(Data_Summary(n).Rate_Map_Corr, Data_Summary(n).Shuffled_Rate_Map_Corr_values, Data_Summary(n).RateMap_Corr_Coherent_Rot);
        C6_saline_RM = RM;
        C6_saline_Shuffle = RM_Shuffle;
    elseif strcmp(Data_Summary(n).animalName, 'C57_6') && strcmp(Data_Summary(n).drug,'saline')   && ~isempty(C6_saline_RM)
        [RM, RM_Shuffle] = get_RM_values_ready(Data_Summary(n).Rate_Map_Corr, Data_Summary(n).Shuffled_Rate_Map_Corr_values, Data_Summary(n).RateMap_Corr_Coherent_Rot);
        C6_saline_RM = cat(1,C6_saline_RM,RM);
        C6_saline_Shuffle = cat(1,C6_saline_Shuffle,RM_Shuffle);
    end
end
[C6sf,C6sx,C6slow,C6shigh] = ecdf(C6_saline_RM,'Function','cdf','Alpha',0.05);
[C6ssf,C6ssx,C6sslow,C6sshigh] = ecdf(C6_saline_Shuffle,'Function','cdf','Alpha',0.05);

C7_saline_RM = [];
for n = 1:size(Data_Summary,2)
    if strcmp(Data_Summary(n).animalName, 'C57_7') && strcmp(Data_Summary(n).drug,'saline')  && isempty(C7_saline_RM)
        [RM, RM_Shuffle] = get_RM_values_ready(Data_Summary(n).Rate_Map_Corr, Data_Summary(n).Shuffled_Rate_Map_Corr_values, Data_Summary(n).RateMap_Corr_Coherent_Rot);
        C7_saline_RM = RM;
        C7_saline_Shuffle = RM_Shuffle;
    elseif strcmp(Data_Summary(n).animalName, 'C57_7') && strcmp(Data_Summary(n).drug,'saline')   && ~isempty(C7_saline_RM)
        [RM, RM_Shuffle] = get_RM_values_ready(Data_Summary(n).Rate_Map_Corr, Data_Summary(n).Shuffled_Rate_Map_Corr_values, Data_Summary(n).RateMap_Corr_Coherent_Rot);
        C7_saline_RM = cat(1,C7_saline_RM,RM);
        C7_saline_Shuffle = cat(1,C7_saline_Shuffle,RM_Shuffle);
    end
end
[C7sf,C7sx,C7slow,C7shigh] = ecdf(C7_saline_RM,'Function','cdf','Alpha',0.05);
[C7ssf,C7ssx,C7sslow,C7sshigh] = ecdf(C7_saline_Shuffle,'Function','cdf','Alpha',0.05);

C8_saline_RM = [];
for n = 1:size(Data_Summary,2)
    if strcmp(Data_Summary(n).animalName, 'C57_8') && strcmp(Data_Summary(n).drug,'saline')  && isempty(C8_saline_RM)
        [RM, RM_Shuffle] = get_RM_values_ready(Data_Summary(n).Rate_Map_Corr, Data_Summary(n).Shuffled_Rate_Map_Corr_values, Data_Summary(n).RateMap_Corr_Coherent_Rot);
        C8_saline_RM = RM;
        C8_saline_Shuffle = RM_Shuffle;
    elseif strcmp(Data_Summary(n).animalName, 'C57_8') && strcmp(Data_Summary(n).drug,'saline')   && ~isempty(C8_saline_RM)
        [RM, RM_Shuffle] = get_RM_values_ready(Data_Summary(n).Rate_Map_Corr, Data_Summary(n).Shuffled_Rate_Map_Corr_values, Data_Summary(n).RateMap_Corr_Coherent_Rot);
        C8_saline_RM = cat(1,C8_saline_RM,RM);
        C8_saline_Shuffle = cat(1,C8_saline_Shuffle,RM_Shuffle);
    end
end
[C8sf,C8sx,C8slow,C8shigh] = ecdf(C8_saline_RM,'Function','cdf','Alpha',0.05);
[C8ssf,C8ssx,C8sslow,C8sshigh] = ecdf(C8_saline_Shuffle,'Function','cdf','Alpha',0.05);

%% Organize data for saline

% get saline CDF mean
A = cat(1,C5sf,C6sf,C7sf,C8sf);
saline_F = sort(A);
saline_F = cat(1, 0, saline_F, 1);

% get saline CDF x-steps
B = cat(1,C5sx,C6sx,C7sx,C8sx);
saline_X = sort(B);
saline_X = cat(1, -1, saline_X, 1);

% get saline CDF high bound mean
C = cat(1,C5shigh,C6shigh,C7shigh,C8shigh);
saline_H = sort(C);

% get saline CDF low bound mean
D = cat(1,C5slow,C6slow,C7slow,C8slow);
saline_L = sort(D);

%% 24h altered contexts data
C5_AB_RM = [];
for n = 1:size(Data_Summary,2)
    if strcmp(Data_Summary(n).animalName, 'C57_5') && strcmp(Data_Summary(n).drug,'altered contexts')  && isempty(C5_AB_RM)
        [RM, RM_Shuffle] = get_RM_values_ready(Data_Summary(n).Rate_Map_Corr, Data_Summary(n).Shuffled_Rate_Map_Corr_values, Data_Summary(n).RateMap_Corr_Coherent_Rot);
        C5_AB_RM = RM;
        C5_AB_Shuffle = RM_Shuffle;
    elseif strcmp(Data_Summary(n).animalName, 'C57_5') && strcmp(Data_Summary(n).drug,'altered contexts')   && ~isempty(C5_AB_RM)
        [RM, RM_Shuffle] = get_RM_values_ready(Data_Summary(n).Rate_Map_Corr, Data_Summary(n).Shuffled_Rate_Map_Corr_values, Data_Summary(n).RateMap_Corr_Coherent_Rot);
        C5_AB_RM = cat(1,C5_AB_RM,RM);
        C5_AB_Shuffle = cat(1,C5_AB_Shuffle,RM_Shuffle);
    end
end
[C5abf,C5abx,C5ablow,C5abhigh] = ecdf(C5_AB_RM,'Function','cdf','Alpha',0.05);
[C5sabf,C5sabx,C5sablow,C5sabhigh] = ecdf(C5_AB_Shuffle,'Function','cdf','Alpha',0.05);

C6_AB_RM = [];
for n = 1:size(Data_Summary,2)
    if strcmp(Data_Summary(n).animalName, 'C57_6') && strcmp(Data_Summary(n).drug,'altered contexts')  && isempty(C6_AB_RM)
        [RM, RM_Shuffle] = get_RM_values_ready(Data_Summary(n).Rate_Map_Corr, Data_Summary(n).Shuffled_Rate_Map_Corr_values, Data_Summary(n).RateMap_Corr_Coherent_Rot);
        C6_AB_RM = RM;
        C6_AB_Shuffle = RM_Shuffle;
    elseif strcmp(Data_Summary(n).animalName, 'C57_6') && strcmp(Data_Summary(n).drug,'altered contexts')   && ~isempty(C6_AB_RM)
        [RM, RM_Shuffle] = get_RM_values_ready(Data_Summary(n).Rate_Map_Corr, Data_Summary(n).Shuffled_Rate_Map_Corr_values, Data_Summary(n).RateMap_Corr_Coherent_Rot);
        C6_AB_RM = cat(1,C6_AB_RM,RM);
        C6_AB_Shuffle = cat(1,C6_AB_Shuffle,RM_Shuffle);
    end
end
[C6abf,C6abx,C6ablow,C6abhigh] = ecdf(C6_AB_RM,'Function','cdf','Alpha',0.05);
[C6sabf,C6sabx,C6sablow,C6sabhigh] = ecdf(C6_AB_Shuffle,'Function','cdf','Alpha',0.05);

C7_AB_RM = [];
for n = 1:size(Data_Summary,2)
    if strcmp(Data_Summary(n).animalName, 'C57_7') && strcmp(Data_Summary(n).drug,'altered contexts')  && isempty(C7_AB_RM)
        [RM, RM_Shuffle] = get_RM_values_ready(Data_Summary(n).Rate_Map_Corr, Data_Summary(n).Shuffled_Rate_Map_Corr_values, Data_Summary(n).RateMap_Corr_Coherent_Rot);
        C7_AB_RM = RM;
        C7_AB_Shuffle = RM_Shuffle;
    elseif strcmp(Data_Summary(n).animalName, 'C57_7') && strcmp(Data_Summary(n).drug,'altered contexts')   && ~isempty(C7_AB_RM)
        [RM, RM_Shuffle] = get_RM_values_ready(Data_Summary(n).Rate_Map_Corr, Data_Summary(n).Shuffled_Rate_Map_Corr_values, Data_Summary(n).RateMap_Corr_Coherent_Rot);
        C7_AB_RM = cat(1,C7_AB_RM,RM);
        C7_AB_Shuffle = cat(1,C7_AB_Shuffle,RM_Shuffle);
    end
end
[C7abf,C7abx,C7ablow,C7abhigh] = ecdf(C7_AB_RM,'Function','cdf','Alpha',0.05);
[C7sabf,C7sabx,C7sablow,C7sabhigh] = ecdf(C7_AB_Shuffle,'Function','cdf','Alpha',0.05);

C8_AB_RM = [];
for n = 1:size(Data_Summary,2)
    if strcmp(Data_Summary(n).animalName, 'C57_8') && strcmp(Data_Summary(n).drug,'altered contexts')  && isempty(C8_AB_RM)
        [RM, RM_Shuffle] = get_RM_values_ready(Data_Summary(n).Rate_Map_Corr, Data_Summary(n).Shuffled_Rate_Map_Corr_values, Data_Summary(n).RateMap_Corr_Coherent_Rot);
        C8_AB_RM = RM;
        C8_AB_Shuffle = RM_Shuffle;
    elseif strcmp(Data_Summary(n).animalName, 'C57_8') && strcmp(Data_Summary(n).drug,'altered contexts')   && ~isempty(C8_AB_RM)
        [RM, RM_Shuffle] = get_RM_values_ready(Data_Summary(n).Rate_Map_Corr, Data_Summary(n).Shuffled_Rate_Map_Corr_values, Data_Summary(n).RateMap_Corr_Coherent_Rot);
        C8_AB_RM = cat(1,C8_AB_RM,RM);
        C8_AB_Shuffle = cat(1,C8_AB_Shuffle,RM_Shuffle);
    end
end
[C8abf,C8abx,C8ablow,C8abhigh] = ecdf(C8_AB_RM,'Function','cdf','Alpha',0.05);
[C8sabf,C8sabx,C8sablow,C8sabhigh] = ecdf(C8_AB_Shuffle,'Function','cdf','Alpha',0.05);

%% Organize data for WT 4h altered contexts

% get WT saline CDF mean
A = cat(1,C5abf,C6abf,C7abf,C8abf);
AB_F = sort(A);
AB_F = cat(1, 0, AB_F, 1);

% get WT saline CDF x-steps
B = cat(1,C5abx,C6abx,C7abx,C8abx);
AB_X = sort(B);
AB_X = cat(1, -1, AB_X, 1);

% get WT saline CDF high bound mean
C = cat(1,C5abhigh,C6abhigh,C7abhigh,C8abhigh);
AB_H = sort(C);

% get WT saline CDF low bound mean
D = cat(1,C5ablow,C6ablow,C7ablow,C8ablow);
AB_L = sort(D);

%% Finally, put shuffle data together

% get shuffle CDF mean
A = cat(1,C5ssf,C6ssf,C7ssf,C8ssf);
Shuffle_F = sort(A);
Shuffle_F = cat(1, 0, Shuffle_F, 1);

% get shuffle CDF x-steps
B = cat(1,C5ssx,C6ssx,C7ssx,C8ssx);
Shuffle_X = sort(B);
Shuffle_X = cat(1, -1, Shuffle_X, 1);

% get shuffle CDF high bound mean
C = cat(1,C5sshigh,C6sshigh,C7sshigh,C8sshigh);
Shuffle_H = sort(C);

% get shuffle CDF low bound mean
D = cat(1,C5sslow,C6sslow,C7sslow,C8sslow);
Shuffle_L = sort(D);


%% plot all data

figure
plot(saline_X,saline_F,'Color','#1750AC' ,'LineWidth',3);
hold on
plot(AB_X,AB_F,'Color','#ff7518','LineWidth',3);
hold on
plot(Shuffle_X,Shuffle_F,'-k','LineWidth',3);
hold on
xlabel('RM Correlation Value')
ylabel('Cumulative Fraction of Cells')
xlim([-0.6,1])
set(gca,'FontSize',20)
% legend('24h same context', '24h altered contexts', 'shuffle', 'Location', 'SouthEast')
set(gca, 'Visible', 'off')
hold off

end